//

#include <WinSock2.h>
#include <windows.h>
#include <iostream>
#include "../src/yet/Thread.h"
#include "../src/yet/Event.h"
#include "../src/yet/win32.h"
#include "../src/yet/Unicode.h"
#include "../src/yet/Handler.h"
#include "../src/yet/AutoLock.h"
#include "../src/yet/Timer.h"
#include "../src/yet/WinLoop.h"
#include "../src/yet/HWNDHandler.h"
#include "../src/yet/net/TcpClient.h"
#include "../src/yet/ftp/EchoParse.h"

using namespace std;
using namespace yet;

void onEvent(TcpClient* client, int event, String buf){
	switch(event){
	case FD_READ:
		cout<<"FD_READ: ["<<buf.cString()<<"]"<<endl;
		break;
	case FD_OOB:
		cout<<"FD_OOB: "<<buf.cString()<<endl;
		break;
	case FD_WRITE:
		cout<<"FD_WRITE"<<endl;
		break;
	case FD_CONNECT:
		cout<<"FD_CONNECT"<<endl;
		break;
	case FD_CLOSE:
		cout<<"FD_CLOSE"<<endl;
		break;
	}
}

static void test() {
	TcpClient client;
	client.OnEvent = onEvent;
	client.open("yangentao.net", 21);
	string s;
	while(cin>>s){
		if(s == "exit" || s == "quit"){
			break;
		}
		cout<<"Send: "<<s<<endl;
		client.send(s);
	}
	client.close();

}

void printEchoParse(EchoParse& p){
	for(size_t i=0; i< p.echos.size(); ++i){
		cout<<p.echos[i].code<<endl;
		vector<string>& lines = p.echos[i].lines;
		for(size_t j=0; j< lines.size(); ++j){
			cout<<"    "<<lines[j]<<endl;
		}
	}
}
void test2(){
	string s="200 OK\n300 bad\n400-abc\n500 test\n400 end\n";

	EchoParse p;
	p.parse(s);
	printEchoParse(p);
}



int main(int argc, char* argv[]) {
	AutoSockLib lib;
//	test();
	test2();
	cout << "Main End" << endl;
	return 0;
}

